<template>
  <el-dialog :visible.sync="currentShowFlag" append-to-body fullscreen :close-on-click-modal="false" :close-on-press-escape="false" @open="handleDialogOpen" @closed="handleDialogClosed">
    <div slot="title" class="detail-dialog__header">{{$t('balance_factory.detailDialog')}}</div>
    <el-tabs v-model="activeTabName">
      <el-tab-pane name="tab1" label="基本情况">
        <simple-form :validate-info="{tabName: 'tab1' }" ref="form_1" :form-field="formField.form_1" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container title="住所地">
          <simple-form :validate-info="{tabName: 'tab1' }" ref="form_2" :form-field="formField.form_2" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab1' }" ref="form_3" :form-field="formField.form_3" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab2" label="改革推进情况">
        <simple-form :validate-info="{tabName: 'tab2' }" ref="form_4" :form-field="formField.form_4" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container title="已发生的改革成本">
          <simple-form :validate-info="{tabName: 'tab2' }" ref="form_5" :form-field="formField.form_5" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab2' }" ref="form_6" :form-field="formField.form_6" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab3" label="资产负债情况">
        <simple-form-container title="期末数">
          <simple-form :validate-info="{tabName: 'tab3' }" ref="form_7" :form-field="formField.form_7" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
      </el-tab-pane>
      <el-tab-pane name="tab4" label="经营情况">
        <simple-form :validate-info="{tabName: 'tab4' }" ref="form_8" :form-field="formField.form_8" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container title="营业收入">
          <simple-form :validate-info="{tabName: 'tab4' }" ref="form_9" :form-field="formField.form_9" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container title="成本费用">
          <simple-form :validate-info="{tabName: 'tab4' }" ref="form_10" :form-field="formField.form_10" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab4' }" ref="form_11" :form-field="formField.form_11" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab5" label="人员情况">
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_12" :form-field="formField.form_12" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_13" :form-field="formField.form_13" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form-container title="主办国有企业派出">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_14" :form-field="formField.form_14" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container title="集体企业员工">
          <simple-form :validate-info="{tabName: 'tab5' }" ref="form_15" :form-field="formField.form_15" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_16" :form-field="formField.form_16" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        <simple-form :validate-info="{tabName: 'tab5' }" ref="form_17" :form-field="formField.form_17" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
      <el-tab-pane name="tab6" label="本年累计在职人员变动情况">
        <simple-form-container title="减员">
          <simple-form :validate-info="{tabName: 'tab6' }" ref="form_18" :form-field="formField.form_18" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form-container title="增员">
          <simple-form :validate-info="{tabName: 'tab6' }" ref="form_19" :form-field="formField.form_19" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
      </el-tab-pane>
      <el-tab-pane name="tab7" label="人员分流安置情况">
        <simple-form-container title="分流安置人数（包括协议解除劳动合同、提前退休及以下形式）">
          <simple-form :validate-info="{tabName: 'tab7' }" ref="form_20" :form-field="formField.form_20" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
        </simple-form-container>
        <simple-form :validate-info="{tabName: 'tab7' }" ref="form_21" :form-field="formField.form_21" v-model="formModel" labelPosition="top" :grid="{xs: 12, sm: 12, md: 6}" :view-flag="viewFlag"></simple-form>
      </el-tab-pane>
    </el-tabs>
    <div slot="footer">
      <el-button @click="handleDialogClose">{{viewFlag ? $t('operation.close') : $t('operation.cancel')}}</el-button>
      <el-button type="primary" @click="handleDataSubmit" v-if="!viewFlag">{{$t('operation.submit')}}</el-button>
    </div>
  </el-dialog>
</template>
<script>
const BASEURL = {
  save: '/Web/BizController/ajax.html?sys_method=Add&sys_objName=Biz_Factory_Collective',
  update: '/Web/BizController/ajax.html?sys_method=Update&sys_objName=Biz_Factory_Collective'
}
export default {
  name: 'balance_factory_detail',
  data () {
    return {
      activeTabName: 'tab1',
      formModel: {}
    }
  },
  inject: ['handleDataSearch'],
  computed: {
    currentShowFlag: {
      get () { return this.showFlag },
      set (val) { this.$emit('update:showFlag', val) }
    },
    formField () {
      return {
        form_1: [
          {
            prop: 'companyname',
            label: '企业名称',
            type: 'Select',
            component: { optionList: this.extData.orgList.map(item => { return { key: item.value, value: item.value, text: item.text } }) },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'uploadyear',
            label: '年份',
            type: 'Datepicker',
            component: { type: 'year', valueFormat: 'yyyy' },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'uploadquarter',
            label: '季度',
            type: 'Select',
            component: { optionList: this.$getDictList('季度') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'hostcompany',
            label: '主办企业',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_2: [
          {
            prop: 'province',
            label: '省',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'citycounty',
            label: '市、县',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_3: [
          {
            prop: 'companytype',
            label: '公司性质',
            type: 'Select',
            component: { optionList: this.$getDictList('公司性质') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'propertytype',
            label: '产权性质',
            type: 'Select',
            component: { optionList: this.$getDictList('产权性质_厂办') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'isconfirmation',
            label: '是否确权',
            type: 'Select',
            component: { optionList: this.$getDictList('是否') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'registeredcapital',
            label: '注册资本',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'equitystructure',
            label: '股权结构',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'managementlevel',
            label: '管理层级',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'businessstatus',
            label: '经营状态',
            type: 'Select',
            component: { optionList: this.$getDictList('经营状态_厂办') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'mainbusiness',
            label: '主营业务',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'insurancelocation',
            label: '职工养老保险关系所在地（省社保/XX市社保）',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_4: [
          {
            prop: 'reformmethod',
            label: '改革方式',
            type: 'Select',
            component: { optionList: this.$getDictList('改革方式_厂办') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          }
        ],
        form_5: [
          {
            prop: 'reformcost',
            label: '改革成本合计',
            type: 'Input',
            component: { viewFlag: true }
          },
          {
            prop: 'assetdebtloss',
            label: '资产债务处置损失',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateReformcost
            }
          },
          {
            prop: 'otherfee',
            label: '关闭注销、破产清算等其他费用',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateReformcost
            }
          },
          {
            prop: 'resettlementcost',
            label: '人员分流安置费用',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateReformcost
            }
          }
        ],
        form_6: [
          {
            prop: 'isrestructuring',
            label: '是否实施公司制改制',
            type: 'Select',
            component: { optionList: this.$getDictList('是否') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'iscompletereform',
            label: '是否已完成改革',
            type: 'Select',
            component: { optionList: this.$getDictList('是否') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          },
          {
            prop: 'reformmeasuresprogress',
            label: '改革措施与进展',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_7: [
          {
            prop: 'totalassets',
            label: '资产总额',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateNetassets
            }
          },
          {
            prop: 'netreceivables',
            label: '其中：应收主办国有企业账款净额',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'netfixedassets',
            label: '占用主办国有企业的固定资产净额',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'totalliabilities',
            label: '负债总额',
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: (rule, value, callback) => {
                  let corporateaccountspayable = Number(this.formModel.corporateaccountspayable) || 0
                  if (Number(value) >= corporateaccountspayable) {
                    callback()
                  } else {
                    callback(new Error('必须大于等于 其中：应付主办企业账款'))
                  }
                }
              }
            ],
            event: {
              change: this.calculateAssetsliabilities
            }
          },
          {
            prop: 'corporateaccountspayable',
            label: '其中：应付主办企业账款',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateNetassets
            }
          },
          {
            prop: 'netassets',
            label: '净资产',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'assetsliabilities',
            label: '资产负债率',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'isinsolvent',
            label: '是否资不抵债',
            type: 'Select',
            component: { optionList: this.$getDictList('是否') },
            rules: { trigger: 'change', message: this.$t('validate.notSelect'), required: true }
          }
        ],
        form_8: [
          { type: 'Title', title: '本年累计', col: { span: 24 } }
        ],
        form_9: [
          {
            prop: 'totalincome',
            label: '收入总额',
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: (rule, value, callback) => {
                  if (Number(value) >= (Number(this.formModel.businessincome || 0))) {
                    callback()
                  } else {
                    callback(new Error('必须大于等于 其中：来自主办国有企业的收入'))
                  }
                }
              }
            ],
            event: {
              change: this.calculateTotalprofit
            }
          },
          {
            prop: 'businessincome',
            label: '其中：来自主办国有企业的收入',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_10: [
          {
            prop: 'totalcost',
            label: '费用总额',
            type: 'NumberInput',
            rules: [
              { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
              {
                // 自定义校验规则
                trigger: 'blur',
                validator: (rule, value, callback) => {
                  let laborcost = Number(this.formModel.laborcost) || 0
                  let interestexpense = Number(this.formModel.interestexpense) || 0
                  let depreciationdepletion = Number(this.formModel.depreciationdepletion) || 0
                  let assetimpairmentloss = Number(this.formModel.assetimpairmentloss) || 0
                  let sum = laborcost + interestexpense + depreciationdepletion + assetimpairmentloss
                  if (Number(value) >= sum) {
                    callback()
                  } else {
                    callback(new Error('必须大于等于 其中：人工成本 + 利息支出 + 折旧折耗 + 资产减值损失'))
                  }
                }
              }
            ],
            event: {
              change: this.calculateTotalprofit
            }
          },
          {
            prop: 'laborcost',
            label: '其中：人工成本',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'interestexpense',
            label: '利息支出',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'depreciationdepletion',
            label: '折旧折耗',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'assetimpairmentloss',
            label: '资产减值损失',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_11: [
          {
            prop: 'totalprofit',
            label: '利润总额',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'profitloss',
            label: '盈亏情况',
            type: 'Select',
            component: { optionList: this.$getDictList('盈亏情况') },
            viewFlag: true
          }
        ],
        form_12: [
          {
            prop: 'totalemployment',
            label: '用工总数合计',
            type: 'Input',
            viewFlag: true
          }
        ],
        form_13: [
          { type: 'Title', title: '在职员工', col: { span: 24 } },
          {
            prop: 'totalemployees',
            label: '在职员工合计',
            type: 'Input',
            viewFlag: true
          }
        ],
        form_14: [
          {
            prop: 'sponsorssendsubtotals',
            label: '主办企业派出小计',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'contractedemployee',
            label: '合同化员工',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSponsorssendsubtotals
            }
          },
          {
            prop: 'marketemployee',
            label: '市场化用工',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSponsorssendsubtotals
            }
          }
        ],
        form_15: [
          {
            prop: 'collectiveenterpriseemployee',
            label: '集体企业员工小计',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'scope1',
            label: '其中：2020年（含）前退休人员',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateCollectiveenterpriseemployee
            }
          },
          {
            prop: 'scope2',
            label: '2020年-2025年（含）前退休人员',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateCollectiveenterpriseemployee
            }
          },
          {
            prop: 'scope3',
            label: '2025年-2030年（含）前退休人员',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateCollectiveenterpriseemployee
            }
          },
          {
            prop: 'scope4',
            label: '2030年以后退休人员',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateCollectiveenterpriseemployee
            }
          }
        ],
        form_16: [
          {
            prop: 'laboremployeecurrent',
            label: '劳务用工',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateTotalemployment
            }
          }
        ],
        form_17: [
          { type: 'Title', title: '离退休人员', col: { span: 24 } },
          {
            prop: 'totalretirees',
            label: '离退休人员合计',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          },
          {
            prop: 'yeartotalretirees',
            label: '其中：本年累计退休人数',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ],
        form_18: [
          {
            prop: 'subtotalreduction',
            label: '减员小计',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'naturalreduction',
            label: '自然减员',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalreduction
            }
          },
          {
            prop: 'agreementcancellation',
            label: '协议解除劳动合同',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalreduction
            }
          },
          {
            prop: 'earlyretirement',
            label: '提前退休',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalreduction
            }
          },
          {
            prop: 'otherreduction',
            label: '其他',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalreduction
            }
          }
        ],
        form_19: [
          {
            prop: 'subtotalincrease',
            label: '增员小计',
            type: 'Input',
            viewFlag: true
          },
          {
            prop: 'mainbusinessemployee',
            label: '主业派出人员',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalincrease
            }
          },
          {
            prop: 'recruitmentmarketemployee',
            label: '招聘的市场化用工',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalincrease
            }
          },
          {
            prop: 'laboremployeeincrease',
            label: '劳务用工',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalincrease
            }
          },
          {
            prop: 'otherincease',
            label: '其他',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateSubtotalincrease
            }
          }
        ],
        form_20: [
          {
            prop: 'totalstaffing',
            label: '人员分流合计（含协议解除劳动合同及提前退休）',
            type: 'Input',
            viewFlag: true,
            col: { span: 24 }
          },
          {
            prop: 'internalretirement',
            label: '内部退养',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateTotalstaffing
            }
          },
          {
            prop: 'leavejob',
            label: '离岗歇业',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateTotalstaffing
            }
          },
          {
            prop: 'agreementreservation',
            label: '协议保留劳动关系',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateTotalstaffing
            }
          },
          {
            prop: 'othertype',
            label: '其他方式',
            type: 'NumberInput',
            component: { decimal: 0 },
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true },
            event: {
              change: this.calculateTotalstaffing
            }
          },
          {
            prop: 'othertypedesc',
            label: '其他方式说明',
            type: 'Input',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }

        ],
        form_21: [
          {
            prop: 'cumulativedefault',
            label: '期末累计拖欠的工资、社保等费用',
            type: 'NumberInput',
            rules: { trigger: 'blur', message: this.$t('validate.notBlank'), required: true }
          }
        ]
      }
    }
  },
  props: {
    showFlag: { type: Boolean, default: false },
    viewFlag: { type: Boolean },
    detailData: { type: Object },
    extData: { type: Object }
  },
  methods: {
    handleDialogClose () {
      this.currentShowFlag = false
    },
    handleDataSubmit () {
      Promise.all(
        Object.keys(this.formField).map(key => {
          return this.$refs[key].validate()
        })
      )
        .then(resp => {
          let loadingFlag = this.$loading({ target: this.$el.querySelector('.el-dialog') })
          let submitModel = this.$_.cloneDeep(this.formModel)
          if (submitModel.assetsliabilities === '无资产') {
            submitModel.assetsliabilities = 0
          }
          Object.assign(submitModel, { sys_mid: this.extData.sys_mid })
          this.$axios
            .post(this.detailData.id ? BASEURL.update : BASEURL.save, submitModel)
            .then(resp => {
              this.currentShowFlag = false
              this.$message({ type: 'success', message: this.$t('tip.saveSuccess') })
              this.handleDataSearch()
            })
            .finally(() => {
              loadingFlag.close()
            })
        })
        .catch(err => {
          // 跳转到未通过校验的tab，参数是simple-form的validate-info属性传入的
          this.activeTabName = err.tabName
        })
    },
    handleDialogOpen () {
      if (!this.detailData.id) return

      this.detailData.uploadyear = this.detailData.uploadyear + ''
      this.detailData.uploadquarter = this.detailData.uploadquarter + ''
      this.formModel = Object.assign({}, this.formModel, this.$_.cloneDeep(this.detailData))
    },
    handleDialogClosed () {
      Object.keys(this.formField).forEach(key => {
        this.$refs[key].resetFields()
      })
      this.formModel = {}
      this.activeTabName = 'tab1'
    },

    calculateReformcost () {
      // 计算 改革成本合计
      this.$nextTick(() => {
        let AssetDebtLoss = Number(this.formModel.assetdebtloss) || 0
        let OtherFee = Number(this.formModel.otherfee) || 0
        let ResettlementCost = Number(this.formModel.resettlementcost) || 0
        let result = AssetDebtLoss + OtherFee + ResettlementCost
        this.$set(this.formModel, 'reformcost', result)
      })
    },
    calculateNetassets () {
      // 计算 净资产
      this.$nextTick(() => {
        let totalassets = Number(this.formModel.totalassets) || 0
        let corporateaccountspayable = Number(this.formModel.corporateaccountspayable) || 0
        let result = totalassets - corporateaccountspayable
        this.$set(this.formModel, 'netassets', result)

        // 调用 计算资产负债率
        this.calculateAssetsliabilities()
      })
    },
    calculateAssetsliabilities () {
      // 计算 资产负债率
      this.$nextTick(() => {
        let totalassets = Number(this.formModel.totalassets) || 0
        let totalliabilities = Number(this.formModel.totalliabilities) || 0
        let result = totalliabilities / totalassets
        if (totalassets === 0) {
          this.$set(this.formModel, 'assetsliabilities', '无资产')
        } else {
          this.$set(this.formModel, 'assetsliabilities', result)
        }
      })
    },
    calculateTotalprofit () {
      // 计算 利润总额
      this.$nextTick(() => {
        let totalincome = Number(this.formModel.totalincome) || 0
        let totalcost = Number(this.formModel.totalcost) || 0
        let result = totalincome - totalcost
        // 若利润为正则盈利 0则盈亏平衡 负则亏损
        if (result > 0) {
          this.$set(this.formModel, 'profitloss', 'profitLossType1')
        } else if (result < 0) {
          this.$set(this.formModel, 'profitloss', 'profitLossType2')
        } else {
          this.$set(this.formModel, 'profitloss', 'profitLossType3')
        }
        this.$set(this.formModel, 'totalprofit', result)
      })
    },
    calculateSponsorssendsubtotals () {
      // 计算 主办企业派出小计
      this.$nextTick(() => {
        let contractedemployee = Number(this.formModel.contractedemployee) || 0
        let marketemployee = Number(this.formModel.marketemployee) || 0
        let result = contractedemployee + marketemployee
        this.$set(this.formModel, 'sponsorssendsubtotals', result)

        // 调用 计算在职员工合计
        this.calculateTotalemployees()
      })
    },
    calculateCollectiveenterpriseemployee () {
      // 计算 集体企业员工小计
      this.$nextTick(() => {
        let scope1 = Number(this.formModel.scope1) || 0
        let scope2 = Number(this.formModel.scope2) || 0
        let scope3 = Number(this.formModel.scope3) || 0
        let scope4 = Number(this.formModel.scope4) || 0
        let result = scope1 + scope2 + scope3 + scope4
        this.$set(this.formModel, 'collectiveenterpriseemployee', result)

        // 调用 计算在职员工合计
        this.calculateTotalemployees()
      })
    },
    calculateTotalemployees () {
      // 计算 在职员工合计
      this.$nextTick(() => {
        let sponsorssendsubtotals = Number(this.formModel.sponsorssendsubtotals) || 0
        let collectiveenterpriseemployee = Number(this.formModel.collectiveenterpriseemployee) || 0
        let result = sponsorssendsubtotals + collectiveenterpriseemployee
        this.$set(this.formModel, 'totalemployees', result)

        // 调用 计算用工总数合计
        this.calculateTotalemployment()
      })
    },
    calculateTotalemployment () {
      // 计算 用工总数合计
      this.$nextTick(() => {
        let totalemployees = Number(this.formModel.totalemployees) || 0
        let laboremployeecurrent = Number(this.formModel.laboremployeecurrent) || 0
        let result = totalemployees + laboremployeecurrent
        this.$set(this.formModel, 'totalemployment', result)
      })
    },
    calculateSubtotalreduction () {
      // 计算 减员小计
      this.$nextTick(() => {
        let naturalreduction = Number(this.formModel.naturalreduction) || 0
        let agreementcancellation = Number(this.formModel.agreementcancellation) || 0
        let earlyretirement = Number(this.formModel.earlyretirement) || 0
        let otherreduction = Number(this.formModel.otherreduction) || 0
        let result = naturalreduction + agreementcancellation + earlyretirement + otherreduction
        this.$set(this.formModel, 'subtotalreduction', result)

        // 调用 计算人员分流合计（含协议解除劳动合同及提前退休）
        this.calculateTotalstaffing()
      })
    },
    calculateSubtotalincrease () {
      // 计算 增员小计
      this.$nextTick(() => {
        let mainbusinessemployee = Number(this.formModel.mainbusinessemployee) || 0
        let recruitmentmarketemployee = Number(this.formModel.recruitmentmarketemployee) || 0
        let laboremployeeincrease = Number(this.formModel.laboremployeeincrease) || 0
        let otherincease = Number(this.formModel.otherincease) || 0
        let result = mainbusinessemployee + recruitmentmarketemployee + laboremployeeincrease + otherincease
        this.$set(this.formModel, 'subtotalincrease', result)
      })
    },
    calculateTotalstaffing () {
      // 计算 人员分流合计（含协议解除劳动合同及提前退休）
      this.$nextTick(() => {
        let agreementcancellation = Number(this.formModel.agreementcancellation) || 0
        let earlyretirement = Number(this.formModel.earlyretirement) || 0
        let internalretirement = Number(this.formModel.internalretirement) || 0
        let leavejob = Number(this.formModel.leavejob) || 0
        let agreementreservation = Number(this.formModel.agreementreservation) || 0
        let othertype = Number(this.formModel.othertype) || 0
        let result = agreementcancellation + earlyretirement + internalretirement + leavejob + agreementreservation + othertype
        this.$set(this.formModel, 'totalstaffing', result)
      })
    }
  }
}
</script>
